package com.flyaudio.xiaopengautopilot.util;

import android.os.SystemProperties;
import android.util.Log;

public class L {
	
	private static final String TAG = "XiaoPengAutopilot";
	
	private static final int VERBOSE 	= 1;
	private static final int DEBUG_LEVEL = 2;
	private static final int INFO = 3;
	private static final int WARN = 4;
	private static final int ERROR = 5;
	private static final int NOTHING = 6;
	
	private static final int level = VERBOSE;
	 
    public static final String CONF_LOGCAT_DEBUG = "fly.autopilot.debug";
    public static final String CONF_LOGCAT_DEBUG_ANA = "fly.autopilot.ana";
    public static final String CONF_LOGCAT_DEBUG_ENABLE = "1";
	
	public static void v(String Tag, String msg){
		if(level <= VERBOSE){
				Log.v(TAG, "[" + Tag + "]" + msg);
		}
	}
	
	public static void d(String Tag, String msg)
	{
		if(level <= VERBOSE)
			Log.d(TAG, "[" + Tag + "]" + msg);
	}
	
	public static void D(String Tag, String msg)
	{
		String debug = SystemProperties.get(CONF_LOGCAT_DEBUG, "");
	    if (debug.equals(CONF_LOGCAT_DEBUG_ENABLE))
		Log.d(TAG, "[" + Tag + "]" + msg);
	}
	
	public static void i(String Tag, String msg){
		if(level <= INFO){
			Log.i(TAG, "[" + Tag + "]" + msg);
		}
	}
	
	public static void w(String Tag, String msg){
		if(level <= WARN){
			Log.w(TAG, "[" + Tag + "]" + msg);
		}
	}

	public static void e(String Tag, String msg) {
			Log.e(TAG, "[" + Tag + "]" + msg);
	}
	
	 public static String bytes2HexString(byte[] b, int flag) {
		    String ret = "";
		    Boolean show = false;
		    switch (flag) {
		    case 0:
		      show = true;
		      break;
		    case 1:
		      String debug = SystemProperties.get(CONF_LOGCAT_DEBUG, "");
		      if (debug.equals(CONF_LOGCAT_DEBUG_ENABLE))
		        show = true;
		      break;
		    case 2:
		      debug = SystemProperties.get(CONF_LOGCAT_DEBUG_ANA, "");
		      if (debug.equals(CONF_LOGCAT_DEBUG_ENABLE))
		        show = true;
		      break;
		    default:
		      break;
		    }
		    if (show == true) {
		      try {
		        if (b.length > 0) {
		          for (int i = 0; i < b.length; i++) {
		            String hex = Integer.toHexString(b[i] & 0xFF);
		            if (hex.length() == 1) {
		              hex = '0' + hex;
		            }
		            if (hex.length() == 2) {
		              hex = " " + hex;
		            }
		            ret += hex;
		          }
		        }
		      } catch (Exception e) {
		        Log.e("PageManagerXMLParaser", "err:" + e.toString());
		      }
		    }
		    return ret;
		  }
}
